iT邦幫忙

0

Day 13|ASP.NET Core:實作 CRUD API

c#
  • 分享至 

  • xImage
  •  

今日學習目標

  • 理解 CRUD 四個操作
  • 建立新增任務的 POST API
  • 建立修改任務的 PUT API
  • 建立刪除任務的 DELETE API
  • 成功測試五個 API 路由

什麼是 CRUD

CRUD 是後端開發最基本的四種資料操作。
https://ithelp.ithome.com.tw/upload/images/20261018/20184430AIYnxYTwe1.png
今天要完成以下五個 API:
https://ithelp.ithome.com.tw/upload/images/20261018/2018443064Hil4JtDQ.png

建立新增與修改任務的 DTO

在 DTOs 資料夾新增 CreateTaskDto.cs
https://ithelp.ithome.com.tw/upload/images/20261018/20184430Sj87GcG0w0.png
在 DTOs 資料夾新增 UpdateTaskDto.cs
https://ithelp.ithome.com.tw/upload/images/20261018/20184430SDCh6CVHvJ.png

確認 Program.cs

https://ithelp.ithome.com.tw/upload/images/20261018/20184430yodvWK5uiM.pnghttps://ithelp.ithome.com.tw/upload/images/20261018/20184430T0GFAaPpKG.png

修改 TasksController.cs

https://ithelp.ithome.com.tw/upload/images/20261018/20184430K4bQ8ir0tf.pnghttps://ithelp.ithome.com.tw/upload/images/20261018/201844302rNFapHCTR.pnghttps://ithelp.ithome.com.tw/upload/images/20261018/20184430jrKTsZE2Tf.pnghttps://ithelp.ithome.com.tw/upload/images/20261018/20184430zKovTFdn6p.pnghttps://ithelp.ithome.com.tw/upload/images/20261018/20184430mTr9mZhjqw.png
結果
先dotnet build再dotnet run
https://ithelp.ithome.com.tw/upload/images/20261018/201844308Ou43TA0vH.png


*提醒邦友,使用第三方服務/API 時,請務必評估資安風險與隱私保護
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言